package com.jws.jawestshow;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;

import com.jws.thirdlibrary.CxManager;

public class LedLightActivity extends Activity {
    private static final String TAG = "LedLightActivity";
    private SeekBar seekBar;
    private boolean mTouchInProgress;
    private CxManager mCxManager;
    private int mBrightness;

    private Button btn_get_led_brightness;

    private TextView tv_led_brightness;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ledlight);
        mCxManager = CxManager.create(this);
        mBrightness = mCxManager.jwsGetLEDBrightness();
        Log.v("byf-seekbar", "onCreate mBrightness:" + mBrightness);
        btn_get_led_brightness = (Button) findViewById(R.id.btn_get_led_brightness);
        tv_led_brightness = (TextView) findViewById(R.id.tv_led_brightness);
        seekBar = (SeekBar) findViewById(R.id.seekbar);
        seekBar.setMax(255);
        seekBar.setProgress(mBrightness);
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                Log.v("byf-seekbar", " onProgressChanged seekbar:" + " progress:" + progress
                        + " fromUser:" + fromUser + " mTouchInProgress:" + mTouchInProgress);
                if (mTouchInProgress) {
                    mCxManager.jwsSetLEDBrightness(progress);
                    //   seekBar.setProgress(progress);
                }
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                Log.v("byf-seekbar", "onStartTrackingTouch seekBar:" + seekBar.toString());
                mTouchInProgress = true;
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

                mTouchInProgress = false;
                mBrightness = seekBar.getProgress();
                Log.v("byf-seekbar", "onStopTrackingTouch seekBar:" + mBrightness);
                mCxManager.jwsSetLEDBrightness(mBrightness);
                //	 seekBar.setProgress(mBrightness);
            }
        });

        btn_get_led_brightness.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int brightness = mCxManager.jwsGetLEDBrightness();
                tv_led_brightness.setText(String.valueOf(brightness));
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        mCxManager.jwsSetLEDBrightness(mBrightness);
        Log.v("byf-seekbar", "onResume mBrightness:" + mBrightness);
    }

    @Override
    public void onPause() {
        super.onPause();
        Log.v("byf-seekbar", "onPause mBrightness:" + mBrightness);
        mCxManager.jwsSetLEDBrightness(mBrightness);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mCxManager.jwsCloseLED();
        Log.v("byf-seekbar", "onDestroy mBrightness:" + mBrightness);
    }
}

	
